<?php
function cmp($a, $b) {
	$result = 1;
	if($a[1] == $b[1])
		$result = 0;
	elseif($a[1] > $b[1])
		$result = -1;

	return $result;
}

class ResultsGrid {
	private $questions;	// [x][0] = string, [x][1] = id
	private $rankings;	// [x][0] = candidate object, [x][1] = total
	private $scores;	// [question][name][0] = answer, [question][name][1] = score, [question][name][2] = isImportant, [question][name][3] = explanation
	
	private $q = 0;
	private $r = 0;
	
	public function addQuestion($name, $id) {
		$this->questions[$this->q][0] = $name;
		$this->questions[$this->q][1] = $id;
		$this->q++;
	}
	
	public function getQuestions() {
		return $this->questions;
	}
	
	public function addRanking($candidate, $total) {
		$this->rankings[$this->r][0] = $candidate;
		$this->rankings[$this->r][1] = $total;
		$this->r++;
		
		usort($this->rankings, 'cmp');
	}
	
	public function getRankings() {
		return $this->rankings;
	}
	
	public function addScore($question, $name, $answer, $score, $isimportant, $explanation) {
		$this->scores[$question][$name][0] = $answer;
		$this->scores[$question][$name][1] = $score;
		$this->scores[$question][$name][2] = $isimportant;
		$this->scores[$question][$name][3] = $explanation;
	}
	
	// return answer, score, importance and explanation
	public function getScore($question, $name) {
		return $this->scores[$question][$name];
	}
	
	public function getScoresForQuestion($question) {
		$return;
		
		for($i = 0; $i < $this->r; $i) {
			$name = $this->rankings[$i][0];
			$return[$i] = $this->getScore($question, $name);
		}
		
		return $return;
	}
	
}
?>